package com.xiaojian.blog.controller.admin;

import com.xiaojian.blog.constant.WebConstant;
import com.xiaojian.blog.controller.BaseController;
import com.xiaojian.blog.dto.MetaDto;
import com.xiaojian.blog.dto.Types;
import com.xiaojian.blog.service.MetaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 分类/标签控制器
 */
@Controller
@RequestMapping("admin/category")
public class CategoryController extends BaseController {

    private static final Logger LOGGER = LoggerFactory.getLogger(CategoryController.class);

    @Resource
    private MetaService metaService;

    @GetMapping(value = "")
    public String index(HttpServletRequest request) {
        List<MetaDto> categoryList = metaService.getMetaList(Types.CATEGORY.getType(), null, WebConstant.MAX_POSTS);
        List<MetaDto> tagList = metaService.getMetaList(Types.TAG.getType(), null, WebConstant.MAX_POSTS);
        request.setAttribute("categories", categoryList);
        request.setAttribute("tags", tagList);
        return "admin/category";
    }

}
